<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="项目编号" prop="projectNo">
        <el-input
          v-model="queryParams.projectNo"
          placeholder="请输入项目编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="合同编号" prop="contractNo">
        <el-input
          v-model="queryParams.contractNo"
          placeholder="请输入合同编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="标段" prop="projectSection">
        <el-input
          v-model="queryParams.projectSection"
          placeholder="请输入标段"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="计划开工日期" prop="plannedStartDate">
        <el-date-picker clearable
          v-model="queryParams.plannedStartDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择计划开工日期">
        </el-date-picker>
      </el-form-item> -->
      <!-- <el-form-item label="计划竣工日期" prop="plannedEndDate">
        <el-date-picker clearable
          v-model="queryParams.plannedEndDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择计划竣工日期">
        </el-date-picker>
      </el-form-item> -->
      <!-- <el-form-item label="实际开工日期" prop="actualStartDate">
        <el-date-picker clearable
          v-model="queryParams.actualStartDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择实际开工日期">
        </el-date-picker>
      </el-form-item> -->
      <!-- <el-form-item label="实际竣工日期" prop="actualEndDate">
        <el-date-picker clearable
          v-model="queryParams.actualEndDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择实际竣工日期">
        </el-date-picker>
      </el-form-item> -->
      <!-- <el-form-item label="联系人" prop="contactUser">
        <el-input
          v-model="queryParams.contactUser"
          placeholder="请输入联系人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="联系人电话" prop="contactPhone">
        <el-input
          v-model="queryParams.contactPhone"
          placeholder="请输入联系人电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="承包商id(施工单位)" prop="contractorId">
        <el-input
          v-model="queryParams.contractorId"
          placeholder="请输入承包商id(施工单位)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="承包商名称(施工单位)" prop="contractorName">
        <el-input
          v-model="queryParams.contractorName"
          placeholder="请输入承包商名称(施工单位)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="监理单位名称" prop="supervisionUnit">
        <el-input
          v-model="queryParams.supervisionUnit"
          placeholder="请输入监理单位名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="监理单位工程师" prop="supervisionEngineer">
        <el-input
          v-model="queryParams.supervisionEngineer"
          placeholder="请输入监理单位工程师"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="承包商负责人ID(sys_user表id)" prop="contractorLeaderId">
        <el-input
          v-model="queryParams.contractorLeaderId"
          placeholder="请输入承包商负责人ID(sys_user表id)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="承包商(施工单位)负责人" prop="contractorLeader">
        <el-input
          v-model="queryParams.contractorLeader"
          placeholder="请输入承包商(施工单位)负责人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="承包商(施工单位)安全负责人" prop="contractorSafetyLeader">
        <el-input
          v-model="queryParams.contractorSafetyLeader"
          placeholder="请输入承包商(施工单位)安全负责人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="建设(业主)单位负责人ID(sys_user表id)" prop="ownerLeaderId">
        <el-input
          v-model="queryParams.ownerLeaderId"
          placeholder="请输入建设(业主)单位负责人ID(sys_user表id)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="建设(业主)单位负责人" prop="ownerLeader">
        <el-input
          v-model="queryParams.ownerLeader"
          placeholder="请输入建设(业主)单位负责人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="建设(业主)单位安全负责人" prop="ownerSafetyLeader">
        <el-input
          v-model="queryParams.ownerSafetyLeader"
          placeholder="请输入建设(业主)单位安全负责人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="考核人ID" prop="evaluatorIds">
        <el-input
          v-model="queryParams.evaluatorIds"
          placeholder="请输入考核人ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="考核人姓名" prop="evaluatorNames">
        <el-input
          v-model="queryParams.evaluatorNames"
          placeholder="请输入考核人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['project:project:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['project:project:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['project:project:remove']"
        >删除</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['project:project:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="projectList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="项目主键id" align="center" prop="id" />
      <el-table-column label="项目编号" align="center" prop="projectNo" />
      <el-table-column label="项目名称" align="center" prop="projectName" />
      <el-table-column label="项目类型" align="center" prop="projectType" />
      <el-table-column label="合同编号" align="center" prop="contractNo" />
      <el-table-column label="标段" align="center" prop="projectSection" />
      <el-table-column label="计划开工日期" align="center" prop="plannedStartDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.plannedStartDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="计划竣工日期" align="center" prop="plannedEndDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.plannedEndDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="实际开工日期" align="center" prop="actualStartDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.actualStartDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="实际竣工日期" align="center" prop="actualEndDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.actualEndDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="联系人" align="center" prop="contactUser" />
      <el-table-column label="联系人电话" align="center" prop="contactPhone" />
      <el-table-column label="承包商id(施工单位)" align="center" prop="contractorId" />
      <el-table-column label="承包商名称(施工单位)" align="center" prop="contractorName" />
      <el-table-column label="监理单位名称" align="center" prop="supervisionUnit" />
      <el-table-column label="监理单位工程师" align="center" prop="supervisionEngineer" />
      <el-table-column label="承包商负责人ID(sys_user表id)" align="center" prop="contractorLeaderId" />
      <el-table-column label="承包商(施工单位)负责人" align="center" prop="contractorLeader" />
      <el-table-column label="承包商(施工单位)安全负责人" align="center" prop="contractorSafetyLeader" />
      <el-table-column label="建设(业主)单位负责人ID(sys_user表id)" align="center" prop="ownerLeaderId" />
      <el-table-column label="建设(业主)单位负责人" align="center" prop="ownerLeader" />
      <el-table-column label="建设(业主)单位安全负责人" align="center" prop="ownerSafetyLeader" />
      <el-table-column label="考核人ID" align="center" prop="evaluatorIds" />
      <el-table-column label="考核人姓名" align="center" prop="evaluatorNames" />
      <el-table-column label="状态: 0信息收集中 1开工待审 2施工中 3验收" align="center" prop="status" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['project:project:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['project:project:remove']"
          >删除</el-button>
          <el-dropdown size="mini">
            <el-button size="mini" type="text">
              更多<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="handleView(scope.row)">
                <i class="el-icon-view"></i> 查看
              </el-dropdown-item>
              <el-dropdown-item @click.native="handleProjectMaterials(scope.row)">
                <i class="el-icon-document"></i> 项目资料
              </el-dropdown-item>
              <el-dropdown-item @click.native="handleSafetyDisclosure(scope.row)">
                <i class="el-icon-shield"></i> 安全交底
              </el-dropdown-item>
              <el-dropdown-item @click.native="handleProjectMembers(scope.row)">
                <i class="el-icon-user"></i> 项目成员
              </el-dropdown-item>
              <el-dropdown-item @click.native="handleProjectAssessment(scope.row)">
                <i class="el-icon-check"></i> 项目考核
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改承包商项目对话框 -->
    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="项目编号" prop="projectNo">
          <el-input v-model="form.projectNo" placeholder="请输入项目编号" />
        </el-form-item>
        <el-form-item label="项目名称" prop="projectName">
          <el-input v-model="form.projectName" placeholder="请输入项目名称" />
        </el-form-item>
        <el-form-item label="合同编号" prop="contractNo">
          <el-input v-model="form.contractNo" placeholder="请输入合同编号" />
        </el-form-item>
        <el-form-item label="标段" prop="projectSection">
          <el-input v-model="form.projectSection" placeholder="请输入标段" />
        </el-form-item>
        <el-form-item label="计划开工日期" prop="plannedStartDate">
          <el-date-picker clearable
            v-model="form.plannedStartDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择计划开工日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="计划竣工日期" prop="plannedEndDate">
          <el-date-picker clearable
            v-model="form.plannedEndDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择计划竣工日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="实际开工日期" prop="actualStartDate">
          <el-date-picker clearable
            v-model="form.actualStartDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择实际开工日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="实际竣工日期" prop="actualEndDate">
          <el-date-picker clearable
            v-model="form.actualEndDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择实际竣工日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="联系人" prop="contactUser">
          <el-input v-model="form.contactUser" placeholder="请输入联系人" />
        </el-form-item>
        <el-form-item label="联系人电话" prop="contactPhone">
          <el-input v-model="form.contactPhone" placeholder="请输入联系人电话" />
        </el-form-item>
        <el-form-item label="承包商id(施工单位)" prop="contractorId">
          <el-input v-model="form.contractorId" placeholder="请输入承包商id(施工单位)" />
        </el-form-item>
        <el-form-item label="承包商名称(施工单位)" prop="contractorName">
          <el-input v-model="form.contractorName" placeholder="请输入承包商名称(施工单位)" />
        </el-form-item>
        <el-form-item label="监理单位名称" prop="supervisionUnit">
          <el-input v-model="form.supervisionUnit" placeholder="请输入监理单位名称" />
        </el-form-item>
        <el-form-item label="监理单位工程师" prop="supervisionEngineer">
          <el-input v-model="form.supervisionEngineer" placeholder="请输入监理单位工程师" />
        </el-form-item>
        <el-form-item label="承包商负责人ID(sys_user表id)" prop="contractorLeaderId">
          <el-input v-model="form.contractorLeaderId" placeholder="请输入承包商负责人ID(sys_user表id)" />
        </el-form-item>
        <el-form-item label="承包商(施工单位)负责人" prop="contractorLeader">
          <el-input v-model="form.contractorLeader" placeholder="请输入承包商(施工单位)负责人" />
        </el-form-item>
        <el-form-item label="承包商(施工单位)安全负责人" prop="contractorSafetyLeader">
          <el-input v-model="form.contractorSafetyLeader" placeholder="请输入承包商(施工单位)安全负责人" />
        </el-form-item>
        <el-form-item label="建设(业主)单位负责人ID(sys_user表id)" prop="ownerLeaderId">
          <el-input v-model="form.ownerLeaderId" placeholder="请输入建设(业主)单位负责人ID(sys_user表id)" />
        </el-form-item>
        <el-form-item label="建设(业主)单位负责人" prop="ownerLeader">
          <el-input v-model="form.ownerLeader" placeholder="请输入建设(业主)单位负责人" />
        </el-form-item>
        <el-form-item label="建设(业主)单位安全负责人" prop="ownerSafetyLeader">
          <el-input v-model="form.ownerSafetyLeader" placeholder="请输入建设(业主)单位安全负责人" />
        </el-form-item>
        <el-form-item label="考核人ID" prop="evaluatorIds">
          <el-input v-model="form.evaluatorIds" placeholder="请输入考核人ID" />
        </el-form-item>
        <el-form-item label="考核人姓名" prop="evaluatorNames">
          <el-input v-model="form.evaluatorNames" placeholder="请输入考核人姓名" />
        </el-form-item>
        <el-form-item label="删除标志" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listProject, getProject, delProject, addProject, updateProject } from "@/api/cbs/project/project"

export default {
  name: "AllProject",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 承包商项目表格数据
      projectList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectNo: null,
        projectName: null,
        projectType: null,
        contractNo: null,
        projectSection: null,
        plannedStartDate: null,
        plannedEndDate: null,
        actualStartDate: null,
        actualEndDate: null,
        contactUser: null,
        contactPhone: null,
        contractorId: null,
        contractorName: null,
        supervisionUnit: null,
        supervisionEngineer: null,
        contractorLeaderId: null,
        contractorLeader: null,
        contractorSafetyLeader: null,
        ownerLeaderId: null,
        ownerLeader: null,
        ownerSafetyLeader: null,
        evaluatorIds: null,
        evaluatorNames: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询承包商项目列表 */
    getList() {
      this.loading = true
      listProject(this.queryParams).then(response => {
        this.projectList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        projectNo: null,
        projectName: null,
        projectType: null,
        contractNo: null,
        projectSection: null,
        plannedStartDate: null,
        plannedEndDate: null,
        actualStartDate: null,
        actualEndDate: null,
        contactUser: null,
        contactPhone: null,
        contractorId: null,
        contractorName: null,
        supervisionUnit: null,
        supervisionEngineer: null,
        contractorLeaderId: null,
        contractorLeader: null,
        contractorSafetyLeader: null,
        ownerLeaderId: null,
        ownerLeader: null,
        ownerSafetyLeader: null,
        evaluatorIds: null,
        evaluatorNames: null,
        status: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加承包商项目"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getProject(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改承包商项目"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateProject(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addProject(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除承包商项目编号为"' + ids + '"的数据项？').then(function() {
        return delProject(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('project/project/export', {
        ...this.queryParams
      }, `project_${new Date().getTime()}.xlsx`)
    },
    /** 查看项目详情 */
    handleView(row) {
      // 查看项目详情的具体实现
      console.log('查看项目详情:', row)
    },
    
    /** 查看项目资料 */
    handleProjectMaterials(row) {
      // 查看项目资料的具体实现
      console.log('查看项目资料:', row)
    },
    
    /** 安全交底 */
    handleSafetyDisclosure(row) {
      // 安全交底的具体实现
      console.log('安全交底:', row)
    },
    
    /** 查看项目成员 */
    handleProjectMembers(row) {
      // 查看项目成员的具体实现
      console.log('查看项目成员:', row)
    },
    
    /** 项目考核 */
    handleProjectAssessment(row) {
      // 项目考核的具体实现
      console.log('项目考核:', row)
    },
  }
}
</script>
